package ${config.packageController};

import ${config.packageEntity}.${tableInfo.javaName}${config.suffixEntity};
import ${config.packageService}.${tableInfo.javaName}${config.suffixService};

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ${tableInfo.dbName}表控制层<#if tableInfo.comment?? && (tableInfo.comment?length>0)>, ${tableInfo.comment}</#if>
 *
 * @author ${config.author}
 * @date ${.now?string("yyyy-MM-dd HH:mm:ss")}
 */
@RestController
@RequestMapping({"/${utils.getLowerFirst(tableInfo.javaName)}"})
public class ${tableInfo.javaName}${config.suffixController}{

    @Autowired
    private ${tableInfo.javaName}${config.suffixService} ${utils.getLowerFirst(tableInfo.javaName)}${config.suffixService};

    /**
     * 新增数据
     *
     * @param ${utils.getLowerFirst(tableInfo.javaName)} 实体对象
     * @return 新增结果
     */
    @PostMapping("/insert")
    public String insert(@RequestBody ${tableInfo.javaName}${config.suffixEntity} ${utils.getLowerFirst(tableInfo.javaName)}) {
    this.${utils.getLowerFirst(tableInfo.javaName)}${config.suffixService}.insert(${utils.getLowerFirst(tableInfo.javaName)});
    return "ok";
    }

    /**
     * 修改数据
     *
     * @param ${utils.getLowerFirst(tableInfo.javaName)} 实体对象
     * @return 修改结果
     */
    @PostMapping("/update")
    public String update(@RequestBody ${tableInfo.javaName}${config.suffixEntity} ${utils.getLowerFirst(tableInfo.javaName)}) {
        this.${utils.getLowerFirst(tableInfo.javaName)}${config.suffixService}.update(${utils.getLowerFirst(tableInfo.javaName)});
        return "ok";
    }

    /**
     * 查询列表
     *
     * @param ${utils.getLowerFirst(tableInfo.javaName)} 实体对象
     * @return
     */
    @PostMapping("/findList")
    public List<${tableInfo.javaName}${config.suffixEntity}> findList(@RequestBody ${tableInfo.javaName}${config.suffixEntity} ${utils.getLowerFirst(tableInfo.javaName)}) {
        return this.${utils.getLowerFirst(tableInfo.javaName)}${config.suffixService}.findList(${utils.getLowerFirst(tableInfo.javaName)});
    }

    /**
     * 查询单个
     *
    <#list tableInfo.primaryKeyColumns as col>
     * @param ${col.javaName}
    </#list>
     * @return
     */
    @PostMapping("/findOne")
    public ${tableInfo.javaName}${config.suffixEntity} findOne(<#list tableInfo.primaryKeyColumns as col>@RequestParam ${utils.getSimpleTypeName(col.javaType)} ${col.javaName}<#if col?has_next>, </#if></#list>){
        return this.${utils.getLowerFirst(tableInfo.javaName)}${config.suffixService}.getBy${utils.getUpperCamel(tableInfo.primaryKey)}(<#list tableInfo.primaryKeyColumns as col>${col.javaName}<#if col?has_next>, </#if></#list>);
    }

}